var api = require('../../config/api.js');

Page({
  /**
   * 页面的初始数据
   */
  data: {
    electricianCode: '',
    wordNum: 0,
    sameMonthCompleteNum: 0,
    mAverageScoreToCustomer: 0,
    mAverageScoreToAdmin: 0,
    workOrderChartData: {},
    evaluateCustomerChartData: {},
    evaluateAdminChartData: {},
      //您可以通过修改 config-ucharts.js 文件中下标为 ['pie'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
      opts: {
        color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
        padding: [5,5,5,5],
        enableScroll: false,
        extra: {
          pie: {
            activeOpacity: 0.5,
            activeRadius: 10,
            offsetAngle: 0,
            labelWidth: 15,
            border: false,
            borderWidth: 3,
            borderColor: "#FFFFFF"
          }
        }
      }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.doHttpWorkOrderData();
    this.doHttpEvaluateData();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  /**
   * 获取工单数据
   */
  doHttpWorkOrderData: function () {
    wx.getStorage({
        key: 'electricianCode',
        success: (RES) => {
            this.setData({
                electricianCode: RES.data.electricianCode,
            })
            var that = this
            wx.request({
              url: api.getElectricianStatisticsWorkOrder,
              method: 'POST',
              data: {
                electricianCode: this.data.electricianCode
              },
              success: function (res) {
                if (res.data.code == 200) {
                    console.log('res.data.data关于工单', res.data.data)
                  let mData = {
                    series: [{
                      data: [ {
                        "name": "接单数量",
                        "value": res.data.data.workOrderReceivingNum,
                        "labelText":"接单：" + res.data.data.workOrderReceivingNum + "单"
                      }, {
                        "name": "抢单数量",
                        "value": res.data.data.workOrderCompetitionNum,
                        "labelText":"抢单" + res.data.data.workOrderCompetitionNum + "单"
                      }]
                    }]
                  };
        
                  that.setData({
                    wordNum: res.data.data.workOrderTotalNum,
                    sameMonthCompleteNum: res.data.data.workOrderSameMonthCompleteNum,
                    workOrderChartData: JSON.parse(JSON.stringify(mData))
                  })
                }
              }
            })
        },
    })

  },

  /**
   * 获取评价数据
   */
  doHttpEvaluateData: function () {
    wx.getStorage({
        key: 'electricianCode',
        success: (RES) => {
            this.setData({
                electricianCode: RES.data.electricianCode,
            })
            var that = this
            wx.request({
              url: api.getElectricianStatisticsEvaluate,
              method: 'POST',
              data: {
                electricianCode: 'ELE20241218235907'
              },
              success: function (res) {
                if (res.data.code == 200) {
                    console.log('res.data.data关于评价', res.data.data)
                  let mCustomerData = {
                    series: [{
                      data: [ {
                        "name": "1分",
                        "value": res.data.data.getOnePointsNumToCustomer,
                        "labelText":"1分" + res.data.data.getOnePointsNumToCustomer + "次"
                      }, {
                        "name": "2分",
                        "value": res.data.data.getTwoPointsNumToCustomer,
                        "labelText":"2分" + res.data.data.getTwoPointsNumToCustomer + "次"
                      }, {
                        "name": "3分",
                        "value": res.data.data.getThreePointsNumToCustomer,
                        "labelText":"3分" + res.data.data.getThreePointsNumToCustomer + "次"
                      }, {
                        "name": "4分",
                        "value": res.data.data.getFourPointsNumToCustomer,
                        "labelText":"4分" + res.data.data.getFourPointsNumToCustomer + "次"
                      }, {
                        "name": "5分",
                        "value": res.data.data.getFivePointsNumToCustomer,
                        "labelText":"5分" + res.data.data.getFivePointsNumToCustomer + "次"
                      }]
                    }]
                  };
        
                  let mAdminData = {
                    series: [{
                      data: [ {
                        "name": "1分",
                        "value": res.data.data.getOnePointsNumToAdmin,
                        "labelText":"1分" + res.data.data.getOnePointsNumToAdmin + "次"
                      }, {
                        "name": "2分",
                        "value": res.data.data.getTwoPointsNumToAdmin,
                        "labelText":"2分" + res.data.data.getTwoPointsNumToAdmin + "次"
                      }, {
                        "name": "3分",
                        "value": res.data.data.getThreePointsNumToAdmin,
                        "labelText":"3分" + res.data.data.getThreePointsNumToAdmin + "次"
                      }, {
                        "name": "4分",
                        "value": res.data.data.getFourPointsNumToAdmin,
                        "labelText":"4分" + res.data.data.getFourPointsNumToAdmin + "次"
                      }, {
                        "name": "5分",
                        "value": res.data.data.getFivePointsNumToAdmin,
                        "labelText":"5分" + res.data.data.getFivePointsNumToAdmin + "次"
                      }]
                    }]
                  };
        
                  that.setData({
                    mAverageScoreToCustomer: res.data.data.averageScoreToCustomer,
                    mAverageScoreToAdmin: res.data.data.averageScoreToAdmin,
                    evaluateCustomerChartData: JSON.parse(JSON.stringify(mCustomerData)),
                    evaluateAdminChartData: JSON.parse(JSON.stringify(mAdminData))
                  })
                }
              }
            })
        },
    })

  },

})